﻿/*****************************************************************
 *@Copyright all rights reserved © 2014 Yuga
 *@author YUga studio
 *Contact: zengkang007@gmail.com
 *****************************************************************/
package com.oplink.webbase.modules.invoicing.service;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.oplink.webbase.common.persistence.Page;
import com.oplink.webbase.modules.invoicing.entity.GoodsSort;
import com.oplink.webbase.modules.invoicing.dao.GoodsSortDao;



/**
 * 告警Service
 * @author YUga studio
 * @version 2015-01-12
 */
@Component
@Transactional
public class GoodsSortService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(GoodsSortService.class);
	
	@Autowired
	private GoodsSortDao goodsSortDao;
	
	public GoodsSort get(Long id) {
		return goodsSortDao.findOne(id);
	}
	
	public Page<GoodsSort> find(Page<GoodsSort> page, GoodsSort goodsSort) {
		DetachedCriteria dc = goodsSortDao.createDetachedCriteria();
		//添加查询条件
		if (null != goodsSort.getGoodsSortId()
				&& StringUtils.isNotEmpty(goodsSort.getGoodsSortId().toString())) {
			dc.add(Restrictions.like("goodsSortId", "%"+goodsSort.getGoodsSortId()+"%"));
		}
        if (StringUtils.isNotEmpty(goodsSort.getGoodsSortName())){
			dc.add(Restrictions.like("goodsSortName", "%"+goodsSort.getGoodsSortName()+"%"));
		}
		dc.add(Restrictions.eq(GoodsSort.DEL_FLAG, GoodsSort.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return goodsSortDao.find(page, dc);
	}
	
	/**
	  * @function 创建查询
	  **/
	public Page<GoodsSort> getUserGoodsSort(Page<GoodsSort> page, GoodsSort goodsSort) {
		DetachedCriteria dc = goodsSortDao.createDetachedCriteria();
		//添加查询条件
		if (null != goodsSort.getGoodsSortId()
				&& StringUtils.isNotEmpty(goodsSort.getGoodsSortId().toString())) {
			dc.add(Restrictions.like("goodsSortId", "%"+goodsSort.getGoodsSortId()+"%"));
		}
        if (StringUtils.isNotEmpty(goodsSort.getGoodsSortName())){
			dc.add(Restrictions.like("goodsSortName", "%"+goodsSort.getGoodsSortName()+"%"));
		}
		dc.add(Restrictions.eq(GoodsSort.DEL_FLAG, GoodsSort.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return goodsSortDao.find(page, dc);
	}
	
	public GoodsSort getGoodsSort(Long id) {
		return goodsSortDao.findOne(id);
	}

	public void saveGoodsSort(GoodsSort entity) {
		goodsSortDao.save(entity);
	}
	
	public void deleteGoodsSort(Long id) {
		goodsSortDao.delete(id);
	}
	
	@Autowired
	public void setGoodsSortDao(GoodsSortDao goodsSortDao) {
		this.goodsSortDao = goodsSortDao;
	}	
}
